//
//  DetailHeader.m
//  敢唆嘛!
//
//  Created by 教主 on 15/11/25.
//  Copyright © 2015年 zms. All rights reserved.
//

#import "DetailHeader.h"
#import "Device.h"
#import "Define.h"

@interface DetailHeader ()
@property(nonatomic , strong)UIImageView *bigImageView;//封面的imageView
@property(nonatomic , strong)UILabel *titleLabel;//标题
@property(nonatomic , strong)UIImageView *circleImageView;//各色小圈
@property(nonatomic , strong)UILabel *tagLabel;//标签
@property(nonatomic , strong)UIImageView *headImageView;//头像
@property(nonatomic , strong)UILabel *userNameLabel;//用户名称
@property(nonatomic , strong)UILabel *stateLabel;//发布状态
@end

@implementation DetailHeader

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self)
    {
        //    总视图
        UIView *headerView = [[UIView alloc]init];
        
        //    大的imageView
        self.bigImageView = [[UIImageView alloc]initWithFrame:CGRectMake(KSWidth/8, KSWidth/5, KSWidth/4*3, KSWidth/4*3)];
        [headerView addSubview:self.bigImageView];
        
        //    标题
        self.titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, KSWidth+KSWidth/11, KSWidth, space)];
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        [headerView addSubview:self.titleLabel];
        
        //    标签
        self.tagLabel = [[UILabel alloc]initWithFrame:CGRectMake(KSWidth/8*3+space*2.2, KSWidth+KSWidth/8+space*2, space*4, space)];
        self.tagLabel.font = [UIFont systemFontOfSize:13];
        self.tagLabel.textAlignment = NSTextAlignmentCenter;
        self.tagLabel.font = [UIFont systemFontOfSize:15];
        [headerView addSubview:self.tagLabel];
        
        //    小圆圈
        self.circleImageView = [[UIImageView alloc]initWithFrame:CGRectMake(KSWidth/8*3+space, KSWidth+KSWidth/8+space*2, space, space)];
        [headerView addSubview:self.circleImageView];
        
        //    头像
        self.headImageView = [[UIImageView alloc]initWithFrame:CGRectMake(KSWidth/3.5, KSHeight-KSWidth/3, KSWidth / 19, KSWidth / 19)];
        self.headImageView.layer.cornerRadius = KSWidth / 37;
        self.headImageView.layer.masksToBounds = YES;
        [headerView addSubview:self.headImageView];
        
        //    用户名称
        self.userNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.headImageView.frame.size.width + KSWidth/3.2, KSHeight-KSWidth/3, space*8, KSWidth / 19)];
        self.userNameLabel.alpha = 0.8;
        self.userNameLabel.textAlignment = NSTextAlignmentLeft;
        self.userNameLabel.font = [UIFont systemFontOfSize:KSWidth / 28];
        [headerView addSubview:self.userNameLabel];
        
        //    发布状态
        self.stateLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.headImageView.frame.size.width + self.userNameLabel.frame.size.width + KSWidth/3.5, KSHeight-KSWidth/3, space*8, KSWidth / 19)];
        self.stateLabel.alpha = 0.6;
        self.stateLabel.textAlignment = NSTextAlignmentCenter;
        self.stateLabel.font = [UIFont systemFontOfSize:KSWidth / 34];
        [headerView addSubview:self.stateLabel];
        
        [self.contentView addSubview:headerView];
    }
    return self;
}

// 传值
- (void)setHomeModel:(HomeModel *)model
{
    // 封面图片
    [self.bigImageView sd_setImageWithURL:[NSURL URLWithString:model.infoTitleImage]];
    self.titleLabel.text = model.infoTitle;
    self.tagLabel.text = model.type;
    if ([self.tagLabel.text isEqualToString:@"真事"])
    {
        self.circleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan"];
    }
    else if ([self.tagLabel.text isEqualToString:@"创作"])
    {
        self.circleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan-3"];
    }
    else if ([self.tagLabel.text isEqualToString:@"游记"])
    {
        self.circleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan-2"];
    }
    else if ([self.tagLabel.text isEqualToString:@"秘密"])
    {
        self.circleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan-1"];
    }
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.userHeader]];
    self.userNameLabel.text = model.userName;
    self.stateLabel.text = [[PrettyDate alloc] prettyDateWithReference:model.createdAt];
}

- (void)setRealityModel:(RealityModel *)model
{
    // 封面图片
    [self.bigImageView sd_setImageWithURL:[NSURL URLWithString:model.infoTitleImage]];
    self.titleLabel.text = model.infoTitle;
    self.tagLabel.text = model.type;
    
    if ([self.tagLabel.text isEqualToString:@"真事"])
    {
        self.circleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan"];
    }
    else if ([self.tagLabel.text isEqualToString:@"创作"])
    {
        self.circleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan-3"];
    }
    else if ([self.tagLabel.text isEqualToString:@"游记"])
    {
        self.circleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan-2"];
    }
    else if ([self.tagLabel.text isEqualToString:@"秘密"])
    {
        self.circleImageView.image = [UIImage imageNamed:@"iconfont-yuanquan-1"];
    }
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.userHeader]];
    self.userNameLabel.text = model.userName;
    self.stateLabel.text = [[PrettyDate alloc] prettyDateWithReference:model.createdAt];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
